


//
//  CAAnimationGroupController.m
//  界面动画集
//
//  Created by YYY on 2017/7/3.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "CAAnimationGroupController.h"

@interface CAAnimationGroupController ()

@property(nonatomic,strong)UIImageView *pearImageView;

@end

@implementation CAAnimationGroupController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"CAAnimationGroup";
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"动画组" style:UIBarButtonItemStylePlain target:self action:@selector(animationGroup)];
    [self.view addSubview:self.pearImageView];
    // Do any additional setup after loading the view.
}

-(void)animationGroup
{
    //位移
    CABasicAnimation *basicAnimation1 = [CABasicAnimation animationWithKeyPath:@"position.y"];
    basicAnimation1.byValue = [NSValue valueWithCGPoint:CGPointMake(70, 70)];
    
    //透明度
    CABasicAnimation *basicAnimation2 = [CABasicAnimation animationWithKeyPath:@"opacity"];
    basicAnimation2.fromValue = @(1.0);
    basicAnimation2.toValue = @(0.7);
    
    //大小
    CABasicAnimation *basicAnimation3 = [CABasicAnimation animationWithKeyPath:@"bounds"];
    
    //basicAnimation3.byValue = [NSValue valueWithCGSize:CGSizeMake(150, 150)];
    basicAnimation3.byValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 150, 150)];
    
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.duration = 2.0f;
    group.animations = @[basicAnimation1,basicAnimation2,basicAnimation3];
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [self.pearImageView.layer addAnimation:group forKey:nil];
}

-(UIImageView *)pearImageView
{
    if (!_pearImageView)
    {
        _pearImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pear"]];
        //_pearImageView.center = self.view.center;
        _pearImageView.frame = CGRectMake(50, 200, 100, 100);
    }
    return  _pearImageView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
